package gcu.module.property_money.rest;

import gcu.module.property_money.daomain.PropertyMoney;
import gcu.module.property_money.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.ejb.Remote;
import java.util.Map;

/**
 * Created by haol on 2016/9/25.
 */
@RestController
@RequestMapping("/rest/money")
public class MoneyRestController {

      @Autowired
      private MoneyService moneyService;

      @RequestMapping(value = "/get",method = RequestMethod.GET)
      public Map<String,Object> get(Integer ownerId){
            return moneyService.get(ownerId);
      }

      @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
      public boolean save(@RequestBody PropertyMoney money) {
            if (money.getId() == null){
                  moneyService.addMoney(money);
            }else {
                  moneyService.updateMoney(money);
            }
            return true;
      }

}
